'''
Created on Sep 20, 2011

@author: haddaway
'''

class Packet():
    '''
    This is the primary means of communication to and from the Arduinos.
    This is handled over serial <-> usb
    Packets are a maximum size of 128 bits and are divided as follows:
    
     ___________________________Priority______________________________________
    |             |              | ^ |             |                          |
    | Device Type |   Device ID  |   |   Status    |          Data            |
    |_____________|______________|___|___________ _|__________________________|
        16 Bits       12 Bits    4 Bits    16 Bits            80 Bits           = 128 Bits
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.deviceType = ""
        self.deviceID = ""
        self.priority = ""
        self.statusCode = ""
        self.data = ""
        
    def toString(self):
        string = self.deviceType + self.deviceID + self.priority + self.statusCode + self.data + "\n"
        return string
    
    def fillPacket(self, rawPacket):
        self.deviceType = rawPacket[0:4]
        self.deviceID = rawPacket[4:7]
        self.priority = rawPacket[7:8]
        self.statusCode = rawPacket[8:12]
        self.data = rawPacket[12:32]